//index.js
//获取应用实例
const app = getApp()
 const Api = require("../../utils/api.js").API
 var WxParse = require('../../wxParse/wxParse.js');
// const Store = require("../../utils/store.js").store
// const codeZ = require("../../utils/util.js")
Page({
    data: {
       goods:{},
       list:{
         
       },
       show:false,
       sum:0,
       haha:'',
       noShow:false,
       wode:'',
       custNo:'',
       showShre:false,
       showCarid:false,
       showBottom:true,
   
         itemZhi:{},
    },
    onLoad(optins) {
        let that = this;
         if(optins.hasOwnProperty('type')){
             that.setData({
                 showBottom:false
             })
             }else{
                 that.setData({
                     showBottom:true
                 })
             }
        
        if(optins.hasOwnProperty('item')){
            
            bean = {'evNo':optins.item};//测评详情
            let a = optins.item;
            app.globalData.custNo = optins.custNo;
            this.setData({
                wode:optins.item,
                custNo:optins.custNo,
            })
                       
            Api.cpInfoApi(a).then(res=>{
                let aa = res["evaluateInfo"];
              if(aa == null){
                  return;
              }
              aa.evFile  = JSON.parse(aa['evFile']);
              
                let a = aa.evContent;
                if(a != null){
                    WxParse.wxParse('article', 'html',a, that, 10);
                   
                }  
                
                that.setData({
                    goods:aa,
                   
                })
                if(aa.skuNo != null){
                    
                
                Api.getGoodsDetailApi({'skuNo':aa.skuNo}).then(res=>{
                      
                      if(res.code == 0){
                          that.setData({
                              list:res.data,
                              
                          })
                          
                      }
                      
                    
                })}else{
                         that.setData({
                            noShow:true,
                        })
                }         
                
            })    
        }else{ 
        var bean = {};
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.on('acceptDataFromOpenerPage', function(data) {
          
            bean = {'evNo':data.data};//测评详情
            let a = data.data;
            that.setData({
                wode:data.data,
            })
           
            Api.cpInfoApi(a).then(res=>{
                let aa = res["evaluateInfo"];
              if(aa == null){
                  return;
              }
              aa.evFile  = JSON.parse(aa['evFile']);
                console.log(aa);
                let a = aa.evContent;
                if(a != null){      
                       　 WxParse.wxParse('article', 'html',a, that, 10);
                   
                }  
                
                that.setData({
                    goods:aa,
                   
                })
                if(aa.skuNo != null && aa.skuNo != ""){
                    
                
                Api.getGoodsDetailApi({'skuNo':aa.skuNo}).then(res=>{
                      
                      if(res.code == 0){
                          that.setData({
                              list:res.data
                          })
                      }
                          
                })}else{
                         that.setData({
                            noShow:true,
                        })
                }         
                
            })
            
          })    
      }     
 },
  
   
    onShow: function() {
       let myCust = wx.getStorageSync('myCustNo');
        if(myCust.length > 5){
            this.setData({
                showShre: true
            });
            
             // return  wx.showToast({ title: "请先登录！", icon: 'none' });
        }else{
            this.setData({
                showShre: false
            });
        }
 
 var shre = wx.getStorageSync('share');
 
 if (shre != null && shre == 'share') {
     this.setData({
         show: true
     });
 }
    },
    jump:function(){
        let i =this.data.goods;
            
          
        wx.navigateTo({
                url: '../shopDetail/index',
                   success: function(res) {
                     // 通过eventChannel向被打开页面传送数据
                     res.eventChannel.emit('acceptDataFromOpenerPage', { data:i })
                   }
           })
    },
    clickAdd:function(){
        if(this.data.showShre){                      
        var str = this.data.list;
      
             // debugger
        wx.navigateTo({
                 url: '../shouliren/index',
                   success: function(res) {
                     // 通过eventChannel向被打开页面传送数据
                     res.eventChannel.emit('acceptDataFromOpenerPage', { data:str,type:'111801' })
                   }
           })
           
          }else{
            wx.navigateTo({
                url: '../login/index',
              
            })
            
             // wx.showToast({ title: "请先登录！", icon: 'none' });
        }
    },
   sure() {
          wx.setStorageSync("share", "")
          this.setData({
              show: false
          });
      },
      shareNo(){ 
          wx.switchTab({
               url:'../index/index'
          })
          // wx.navigateTo({
          //     url:'../login/index'
          // })
          
          
            // wx.showToast({ title: '请先登录再进行分享', icon: 'none' });
      },
      onShareAppMessage: function() {
         if(!this.data.showShre){
         return    wx.navigateTo({
                 url:'../login/index'
             })
           }
       
          var that = this;
        
       
          let a = this.data.wode;
          let name = this.data.goods.evTitle;
          let cust =  wx.getStorageSync('myCustNo');
          return {      
              title: name,
              path: `/pages/index/index?source=detailPage&sence=`+a+`&custNo=`+cust,
              success: function(res) {
                  // 转发成功之后的回调
                  if (res.errMsg == 'shareAppMessage:ok') {              
                  }
          }
      }
   },
 
      
     
   shouchang:function(){
     
            if(!this.data.showShre){
            return    wx.navigateTo({
                    url:'../login/index'
                })
              }
           
           let that = this;
           var boll = this.data.goods;
           if (boll.clNo != null) {
               Api.deleSCApi(boll.skuNo).then(res => {
                   if (res.code == 0) {
                       that.setData({
                           ['goods.clNo']: null
                       })
                   }
               })
       
           } else {
               let data = {
                   "busiType": "109602",
                   	"evNo": this.data.goods.evNo==null?'':this.data.goods.evNo,
                   "goodsNo": this.data.goods.goodsNo == null?'':this.data.goods.goodsNo,
                   "skuNo": this.data.goods.skuNo == null?'':this.data.goods.skuNo
               }
               Api.saveSCApi(data).then(res => {
                   if (res.code == 0) {
                       that.setData({
                           ['goods.clNo']: 1
                       })
                   }
       
               })
       
           }
       
       
       
   }
   
});
